package com.dubbo2.lib.service;

import com.alibaba.fastjson.JSON;
import com.dubbo2.api.api.Dubbo2Service;
import com.dubbo2.api.dto.DubboBaseDto;
import com.dubbo2.api.dto.req.Dubbo2ParamDto;
import com.dubbo2.lib.entity.User;
import com.dubbo2.lib.jpa.UserRepository;
import com.dubbo2.lib.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class Dubbo2ServiceImpl implements Dubbo2Service {

    @Autowired
    UserMapper userMapper;

    @Autowired
    UserRepository userRepository;

    @Override
    public DubboBaseDto queryDubbo2Consum(Dubbo2ParamDto param) {

        return null;
    }

    @Override
    public DubboBaseDto queryDubbo2Provide(Dubbo2ParamDto param) {
        User user1 = userMapper.select222(param.getId());
        log.info("mybatis查询到user:{}", JSON.toJSONString(user1));
        User user2 = userRepository.findById(param.getId()).orElse(null);
        log.info("jpa查询到user:{}", JSON.toJSONString(user2));
        return new DubboBaseDto("200", "", JSON.toJSONString(user2));
    }
}
